package com.example.diagnodroid;

import java.util.ArrayList;

import com.example.diagnodroid.connexion.BluetoothActivity;
import com.example.diagnodroid.connexion.WifiActivity;
import com.example.diagnodroid.ecran.ColorActivity;
import com.example.diagnodroid.ecran.DrawActivity;
import com.example.diagnodroid.ecran.DrawView;
import com.example.diagnodroid.localisation.GPSActivity;
import com.example.diagnodroid.localisation.OrientationActivity;
import com.example.diagnodroid.memoire.ExternalMemoryActivity;
import com.example.diagnodroid.memoire.InternalMemoryActivity;
import com.example.diagnodroid.memoire.PerfProcessorActivity;
import com.example.diagnodroid.memoire.SystemMemoryActivity;
import com.example.diagnodroid.mouvement.AccelerometerActivity;
import com.example.diagnodroid.mouvement.ProximityActivity;
import com.example.diagnodroid.mouvement.RotationActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class FragmentListTests extends Fragment implements OnItemClickListener {

	WifiManager wifi;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.fragment_list_tests, container,
				false);

		ListView listView = (ListView) view.findViewById(R.id.list_test);

		ArrayList<Test> arrayList = (ArrayList<Test>) getArguments().get(
				"array");
		TestAdapter adapter = new TestAdapter(arrayList, listView.getContext());
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);

		return view;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, final View arg1, int arg2,
			long arg3) {

		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setMessage("Confirmez-vous le lancement du test ?").setTitle(
				"Confirmation");
		builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				// User clicked OK button
				EntryHolder holder = (EntryHolder) arg1.getTag();

				Intent intent = null;

				switch (holder.idTest) {
				case 1:
					intent = new Intent(getActivity(),
							AccelerometerActivity.class);
					startActivity(intent);
					break;

				case 2:
					intent = new Intent(getActivity(), RotationActivity.class);
					startActivity(intent);
					break;

				case 3:
					intent = new Intent(getActivity(), ProximityActivity.class);
					startActivity(intent);
					break;

				case 4:
					intent = new Intent(getActivity(), GPSActivity.class);
					startActivity(intent);
					break;

				case 5:
					intent = new Intent(getActivity(),
							OrientationActivity.class);
					startActivity(intent);
					break;
				case 6:
					intent = new Intent(getActivity(),
							ColorActivity.class);
					startActivity(intent);
					break;
				case 7:
					intent = new Intent(getActivity(),
							DrawActivity.class);
					startActivity(intent);
					break;
				case 8:
					intent = new Intent(getActivity(), WifiActivity.class);
					startActivity(intent);
					break;

				case 9:
					intent = new Intent(getActivity(), BluetoothActivity.class);
					startActivity(intent);
					break;

				case 11:
					intent = new Intent(getActivity(),
							PerfProcessorActivity.class);
					startActivity(intent);
					break;
					
				case 12:
					intent = new Intent(getActivity(),
							SystemMemoryActivity.class);
					startActivity(intent);
					break;

				case 13:
					intent = new Intent(getActivity(),
							InternalMemoryActivity.class);
					startActivity(intent);
					break;

				case 14:
					intent = new Intent(getActivity(),
							ExternalMemoryActivity.class);
					startActivity(intent);
					break;
				default:
					break;
				}
			}
		});
		builder.setNegativeButton("Annuler",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						// User cancelled the dialog
					}
				});
		AlertDialog dialog = builder.show();

	}
}
